package com.ttxz.sample.adapter

import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.ttxz.common.utils.log.LogUtil
import com.ttxz.sample.bean.BannerBean
import com.youth.banner.adapter.BannerAdapter


class MyBannerAdapter(val mdatas:MutableList<BannerBean>): BannerAdapter<BannerBean, MyBannerAdapter.BannerViewHolder>(mdatas) {

    override fun onCreateHolder(parent: ViewGroup?, viewType: Int): BannerViewHolder {
        LogUtil.e("[onCreateHolder]，执行了")
        val imageView =
            ImageView(parent?.context)
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        return BannerViewHolder(imageView)
    }

    override fun onBindView(holder: BannerViewHolder?, data: BannerBean?, position: Int, size: Int) {
        LogUtil.e("[onBindView]，执行了，position=$position，size=$size")
        holder?.imageView?.let {
            Glide.with(it).load(data?.imagePath).into(it)
        }
    }

    class BannerViewHolder(val imageView: ImageView) : RecyclerView.ViewHolder(imageView)
}